package com.example.jikeyoujikeyou.office_sz.view.activity.forget;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.example.jikeyoujikeyou.office_sz.R;
import com.example.jikeyoujikeyou.office_sz.view.activity.register.VPhoneFragment;
import com.example.jikeyoujikeyou.office_sz.view.base.BaseActivity;
import com.example.jikeyoujikeyou.office_sz.view.base.BaseFragment;
import com.example.jikeyoujikeyou.office_sz.view.base.OfficePageAdapter;
import com.example.jikeyoujikeyou.office_sz.view.base.OfficeViewPager;

import java.util.ArrayList;
import java.util.List;

public class ForgetActivity extends BaseActivity implements BaseFragment.OnFragmentSenderMessage {

    OfficeViewPager ovp;
    List<BaseFragment> fragments;
    int currentPostion = 0;
    public static String telephone;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget);
        ovp = (OfficeViewPager) findViewById(R.id.ovp);

        setTitle("忘记密码");

        fragments = new ArrayList<>();
        fragments.add(new VForgetPhoneFragment().setOnFragmentMessage(this));
        fragments.add(new VForgetPasswordFragment().setOnFragmentMessage(this));

        ovp.setMove(false);
        ovp.setAdapter(new OfficePageAdapter(getSupportFragmentManager(), fragments));
        ovp.setCurrentItem(currentPostion);
        getTitleBar().getIv_return().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (currentPostion) {
                    case 0:
                        finish();
                        break;
                    case 1:
                        currentPostion = currentPostion - 1;
                        ovp.setCurrentItem(currentPostion);
                        break;
                }
            }
        });
    }

    @Override
    public <T> void message(BaseFragment fragment, T t) {
        int position = fragments.indexOf(fragment);
        switch (position) {
            case 0:
                ovp.setCurrentItem(position + 1);
                currentPostion = position + 1;
                break;
            case 1:
                //跳转回登陆界面
                telephone = null;
                finish();
                break;
        }
    }

    private void setTitle(String title){
        getTitleBar().getTv_title().setText(title);
    }

}
